package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.StockFlowBillDao;
import com.xbongbong.saas.domain.entity.StockFlowBillEntity;
import com.xbongbong.saas.domain.entity.StockFlowBillEntityExt;
import com.xbongbong.saas.domain.entity.StockFlowBillUpdateEntity;
import com.xbongbong.saas.model.StockFlowBillModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author lee
 * @date  2019-01-28 9:11
 **/
@Service("StockFlowBillModel")
public class StockFlowBillModelImpl implements StockFlowBillModel {
    @Resource
    private StockFlowBillDao stockFlowBillDao;
    /**
     * 根据索引查询数据
     *
     * @param param 查询参数
     * @return List<ProductStockInfoEntity>
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     **/
    @Override
    public List<StockFlowBillEntity> findEntitys(Map<String, Object> param) {
        return stockFlowBillDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return stockFlowBillDao.getEntitysCount(param);
    }

    /**
     * 入库单产品数据插入
     * @param stockFlowBillEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return Integer
     */
    @Override
    public Integer insert(StockFlowBillEntity stockFlowBillEntity) {
        stockFlowBillEntity.setAddTime(DateTimeUtil.getInt());
        stockFlowBillEntity.setUpdateTime(DateTimeUtil.getInt());
        return stockFlowBillDao.insert(stockFlowBillEntity);
    }
    /**
     * 入库单产品数据更新
     * @param stockFlowBillEntity 供应商实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @return Integer
     */
    @Override
    public Integer update(StockFlowBillEntity stockFlowBillEntity) {
        stockFlowBillEntity.setUpdateTime(DateTimeUtil.getInt());
        return stockFlowBillDao.update(stockFlowBillEntity);
    }
    /**
     * 入库单产品数据保存
     * @param stockFlowBillEntity 保存实体
     * @author lee
     * @date 2020/1/13 16:51
     * @since v1.0
     * @version v1.0
     * @throws XbbException 异常
     * @return Integer
     */
    @Override
    public Integer save(StockFlowBillEntity stockFlowBillEntity) {
        if (stockFlowBillEntity.getId() == null || stockFlowBillEntity.getId().equals(0L)) {
            return insert(stockFlowBillEntity);
        }
        return update(stockFlowBillEntity);
    }

    @Override
    public void insertBatch(List<StockFlowBillEntity> stockFlowBillEntityList) throws XbbException {
        stockFlowBillDao.insertBatch(stockFlowBillEntityList);
    }

    @Override
    public Integer updateGreaterThanTime(Collection<StockFlowBillUpdateEntity> updateList, String corpid, Set<String> warehouseKeyList) {
        return stockFlowBillDao.updateGreaterThanTime(updateList, corpid, warehouseKeyList);
    }

    @Override
    public List<StockFlowBillEntity> getLatestFlowBillByWarehouseKey(Map<String, Object> param) {
        return stockFlowBillDao.getLatestFlowBillByWarehouseKey(param);
    }

    @Override
    public Integer deleteByRefIdIn(String corpid, List<Long> refIdIn, List<Integer> businessTypeIn) {
        return stockFlowBillDao.deleteByRefIdIn(corpid, refIdIn, businessTypeIn);
    }

    @Override
    public List<StockFlowBillEntityExt> getFlowInfo(Map<String, Object> param) {
        return stockFlowBillDao.getFlowInfo(param);
    }

    @Override
    public Integer getGroupByEntitysCount(Map<String, Object> param) {
        return stockFlowBillDao.getGroupByEntitysCount(param);
    }

    @Override
    public void updateBatch(Collection<StockFlowBillUpdateEntity> updateList, String corpid, Set<String> warehouseKeyList) {
        stockFlowBillDao.updateBatch(updateList, corpid, warehouseKeyList);
    }

    @Override
    public void deleteAllByCorpId(String corpid) {
        stockFlowBillDao.deleteAllByCorpId(corpid);
    }

    @Override
    public List<StockFlowBillEntity> queryStockFlowbydate(Map<String, Object> param) {
        return stockFlowBillDao.queryStockFlowbydate(param);
    }

    @Override
    public void updateStockFlowById(List<StockFlowBillEntity> stockFlowBillEntityList, String corpid){
        stockFlowBillDao.updateStockFlowById(stockFlowBillEntityList, corpid);
    }

    @Override
    public List<StockFlowBillEntity> queryStockFlowbydateAndId(String corpid, Long date, List<Long>  productId){
        return stockFlowBillDao.queryStockFlowbydateAndId(corpid, date, productId);
    }

    @Override
    public Boolean isExistProductIn(String corpid, List<Long> productIdList) {
        Long existProduct = stockFlowBillDao.isExistProduct(corpid, productIdList);
        return Objects.nonNull(existProduct);
    }

    @Override
    public void deleteByAddTime(Map<String, Object> param) {
        stockFlowBillDao.deleteByAddTime(param);
    }

    @Override
    public List<StockFlowBillEntity> getStockFlowByWarehouseKey(String corpid, List<String> warehouseKeyList){
        return stockFlowBillDao.getStockFlowByWarehouseKey(corpid, warehouseKeyList);
    }

    @Override
    public StockFlowBillEntity getStockFlowBillBytime(String corpid, Long productId, Long warehouseId){
        return stockFlowBillDao.getStockFlowBillBytime(corpid, productId, warehouseId);
    }


    @Override
    public StockFlowBillEntity checkDate(String corpid,Long date,List<Long> productIdList){
        return stockFlowBillDao.checkDate(corpid,date,productIdList);
    }
    @Override
    public List<StockFlowBillEntity> getCheckDate(String corpid,Long date,List<Long> productIdList){
        return stockFlowBillDao.getCheckDate(corpid,date,productIdList);
    }
    @Override

    public StockFlowBillEntity getFirstStockFlowBillBytime(String corpid,Long date) {
        return stockFlowBillDao.getFirstStockFlowBillBytime(corpid, date);
    }
}
